package com.ruoyi.finances.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.finances.domain.TbSubject;
import com.ruoyi.finances.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finances.domain.TbAccountCash;
import com.ruoyi.finances.service.ITbAccountCashService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 现金账户Controller
 *
 * @author ruoyi
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/cash")
public class TbAccountCashController extends BaseController
{
    @Autowired
    private ITbAccountCashService tbAccountCashService;



    @GetMapping("/subjectList/{id}")
    public TableDataInfo getSubjectList(@PathVariable Integer id){

        List<TbSubject> subjectList = tbAccountCashService.subjectList(id);

        return getDataTable(subjectList);
    }
    /**
     * 查询现金账户列表
     */
    @RequiresPermissions("cash:cash:list")
    @GetMapping("/list")
    public TableDataInfo list(TbAccountCash tbAccountCash)
    {
        startPage();
        List<TbAccountCash> list = tbAccountCashService.selectTbAccountCashList(tbAccountCash);
        return getDataTable(list);
    }

    /**
     * 导出现金账户列表
     */
    @RequiresPermissions("cash:cash:export")
    @Log(title = "现金账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAccountCash tbAccountCash)
    {
        List<TbAccountCash> list = tbAccountCashService.selectTbAccountCashList(tbAccountCash);
        ExcelUtil<TbAccountCash> util = new ExcelUtil<TbAccountCash>(TbAccountCash.class);
        util.exportExcel(response, list, "现金账户数据");
    }

    /**
     * 获取现金账户详细信息
     */
    @RequiresPermissions("cash:cash:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbAccountCashService.selectTbAccountCashById(id));
    }

    /**
     * 新增现金账户
     */
    @RequiresPermissions("cash:cash:add")
    @Log(title = "现金账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TbAccountCash tbAccountCash)
    {
        logger.info("添加现金{}",tbAccountCash);
        return toAjax(tbAccountCashService.insertTbAccountCash(tbAccountCash));
    }

    /**
     * 修改现金账户
     */
    @RequiresPermissions("cash:cash:edit")
    @Log(title = "现金账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAccountCash tbAccountCash)
    {
        logger.info("tbAccountCash:"+tbAccountCash);
        return toAjax(tbAccountCashService.updateTbAccountCash(tbAccountCash));
    }

    /**
     * 删除现金账户
     */
    @RequiresPermissions("cash:cash:remove")
    @Log(title = "现金账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbAccountCashService.deleteTbAccountCashByIds(ids));
    }
}
